package com.cloudpan.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloudpan.common.R;
import com.cloudpan.entity.bo.SysFileCopyOrMv;
import com.cloudpan.entity.bo.SysFileInfoBo;
import com.cloudpan.entity.param.FileClassifyParam;
import com.cloudpan.entity.param.TreeParam;
import com.cloudpan.entity.pojo.SysFileInfo;
import com.cloudpan.entity.vo.SysFileInfoVo;
import com.cloudpan.entity.vo.SysFileTreeVo;
import com.cloudpan.service.SysFileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文件信息 前端控制器
 * </p>
 *
 * @author Code Generator
 * @since 2023-11-07
 */
@RestController
@RequestMapping("/sys/file")
@RequiredArgsConstructor
@Api(value = "文件信息控制层", tags = "文件信息控制层")
public class SysFileInfoController {

    private final SysFileInfoService sysFileInfoService;

    @GetMapping("/create")
    @ApiOperation(value = "用户文件夹创建")
    public R createDir(@RequestBody SysFileInfoBo infoBo){
        Boolean result =  sysFileInfoService.create(infoBo);
        return result?R.ok("创建成功"):R.failed("创建失败");
    }

    @PutMapping("/rename")
    @ApiOperation(value = "用户文件夹重命名")
    public R  rename(@RequestBody SysFileInfoBo infoBo){
        Boolean result =  sysFileInfoService.rename(infoBo);
        return result?R.ok("重命名成功"):R.failed("重命名失败");
    }


    @GetMapping("/listByTree")
    @ApiOperation(value = "列出当前用户下所有的文件或文件夹")
    public R<List<SysFileTreeVo>> list(@RequestBody TreeParam param){
        return R.ok(sysFileInfoService.listByTree(param));
    }

    @PostMapping("/rename/file")
    @ApiOperation(value = "修改文件名称 且 不能修改文件后辍名")
    public R renamefile(@RequestBody SysFileInfoBo infoBo){
        String result =  sysFileInfoService.renamefile(infoBo);
        return R.ok("文件名称" + result + "已修改为" + infoBo.getFileName());
    }

    @ApiOperation(value = "(分页)分类查询文件分类 1:视频 2:音频 3:图片 4:文档 5:其他")
    @PostMapping("/classify")
    public R classify(@RequestBody FileClassifyParam param){
        Page<SysFileInfoVo> classinfo =  sysFileInfoService.listClassifyPage(param);
        return R.ok(classinfo);
    }

    @ApiOperation(value = "文件移动")
    @PostMapping("/mvFile")
    public R copyfile(@RequestBody SysFileCopyOrMv copyInfo){
        Boolean result =  sysFileInfoService.mvFile(copyInfo);
        return R.ok(result);
    }


    @ApiOperation(value = "文件复制")
    @PostMapping("/copyFile")
    public R copyFile(@RequestBody SysFileCopyOrMv copyInfo) {
        Boolean result = sysFileInfoService.copyFile(copyInfo);
        return R.ok(result);
    }

    @ApiOperation(value = "文件夹移动")
    @PostMapping("/mvdir")
    public R mvcopy(@RequestBody SysFileCopyOrMv copyInfo){
        Boolean result = sysFileInfoService.mvdir(copyInfo);
        return R.ok(result);
    }

    @ApiOperation(value = "文件夹复制")
    @PostMapping("/copydir")
    public R copydir(@RequestBody SysFileCopyOrMv copyInfo){
        Boolean result = sysFileInfoService.copydir(copyInfo);
        return R.ok(result);
    }

}

